//
//  YYT_LoginViewController.m
//  AudioVisualFeast
//
//  Created by 温晓宇 on 16/1/29.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "YYT_LoginViewController.h"
#import "YYT_LoginView.h"
#import "YYT_RegisterViewController.h"
@interface YYT_LoginViewController ()
<
    YYT_LoginViewDelegate,
    YYT_RegisterViewControllerDelegate
>

@property (nonatomic, strong)YYT_LoginView *loginView;

@end

@implementation YYT_LoginViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.navigationItem.title = @"登录";
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:self action:@selector(backButton:)];
    
    self.loginView = [[YYT_LoginView alloc] initWithFrame:self.view.bounds];
    _loginView.backgroundColor = WHITE_COLOR;
    [self.view addSubview:_loginView];
    _loginView.delegate = self;
    
}
-(void)backButton:(UIBarButtonItem *)btn{
    [self dismissViewControllerAnimated:YES completion:nil];
}
-(void)login{
    [BmobUser loginWithUsernameInBackground:self.loginView.userText.text password:self.loginView.passwordText.text block:^(BmobUser *user, NSError *error) {
        if (user) {
            [self dismissViewControllerAnimated:YES completion:nil];
        }else{
            UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"用户名或密码错误!" preferredStyle:UIAlertControllerStyleAlert];
            UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"好的" style:UIAlertActionStyleCancel handler:nil];
            [alert addAction:cancelAction];
            [self presentViewController:alert animated:YES completion:^{
                
                
            }];
        }
    }];
    
}
-(void)regis{
    YYT_RegisterViewController *regis = [[YYT_RegisterViewController alloc] init];
    regis.delegate = self;
    UINavigationController *regisNa = [[UINavigationController alloc] initWithRootViewController:regis];
    [self presentViewController:regisNa animated:YES completion:nil];
}
- (void)dismissLogin{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
